package com.qf.service.impl;

import com.qf.dao.InventoryDao;

import com.qf.pojo.Druginfo;
import com.qf.pojo.Inventory;
import com.qf.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    InventoryDao inventoryDao;

    @Override
    public List<Inventory> findAll() {
        return inventoryDao.findAll();
    }

    @Override
    public Inventory findById(Inventory inventory ) {
        return inventoryDao.findById(inventory);
    }

    @Override
    public int insert(Inventory inventory) {
        int res = inventoryDao.insert(inventory);
        if(res==1){
            return 1;
        }
        return 0;
    }

    @Override
    public int update(Inventory inventory) {
        int res = inventoryDao.update(inventory);
        if(res==1){
            return 1;
        }
        return 0;
    }

    @Override
    public int delete(Integer id) {
        int res = inventoryDao.delete(id);
        if(res==1){
            return 1;
        }
        return 0;
    }
    /*@Autowired
    InventoryRepository inventoryRepository;
    @Override
    public List<Inventory> findAll() {
        return inventoryRepository.findAll();
    }

    @Override
    public Inventory findById(Integer id) {
     return inventoryRepository.findById(id).get();
     }

    @Override
    public void insertAndUpdate(Inventory inventory) {
        inventoryRepository.saveAndFlush(inventory);
    }

    @Override
    public void delete(Integer id) {
    inventoryRepository.deleteById(id);
    }*/
}
